#include <ctime>
#include <iostream>
#include <fstream>

using namespace std;

void bubbleSort(int list[], int listLength) {
    bool swapped = false;
    for (int i = 0; i < listLength - 1; i++) {
        for (int j = 0; j < listLength - i - 1; j++) {
            if (list[j] > list[j + 1]) {
                swap(list[j], list[j + 1]);
                swapped = true;
            }
        }
        if (swapped == false)
            break;
    }
}

void readFromFile(const char* filename, int list[], int length) {
    ifstream file(filename);
    for (int i = 0; i < length; i++)
        file >> list[i];
    file.close();
}

int main() {
    const int LEN = 5000;
    int a[LEN];
    unsigned int t_start, t_finish;

    readFromFile("input.txt", a, LEN);

    t_start = clock();
    bubbleSort(a, LEN);
    t_finish = clock();

    unsigned int t_work = t_finish - t_start;

    cout << "Sorted in " << t_work << " milliseconds." << endl;

    readFromFile("reverse.txt", a, LEN);

    t_start = clock();
    bubbleSort(a, LEN);
    t_finish = clock();

    t_work = t_finish - t_start;

    cout << "Sorted in " << t_work << " milliseconds." << endl;

    return 0;
}